package edu.utd.text.game.designer.ui;

import java.util.Scanner;

import edu.utd.text.game.controller.commands.GameCommand;
import edu.utd.text.game.designer.controller.DesignerController;
import edu.utd.text.game.designer.exceptions.ExitRequestException;
import edu.utd.text.game.domain.exceptions.UserInputParseException;

public class DesignerConsoleProxy {
	DesignerController controller = DesignerController.INSTANCE;
	Scanner scanner;
	
	public DesignerConsoleProxy() {
		this(new Scanner(System.in));
	}
	
	public DesignerConsoleProxy(Scanner scanner) {
		this.scanner = scanner;
	}
	
	public void runDesigner() {
		
		System.out.println("### Welcome to the UTD Text Game Designer ###");
		
		while (true) {
			try {
				String outcome = processInput();
				System.out.println(outcome);
			} catch (UserInputParseException uipx) {
				System.out.println("SYNTAX ERROR");
			} catch (ExitRequestException erx) {
				System.out.println("Exiting the design tool app.");
				break;

				
	// TODO : Are you sure you want to exit?  Can't figure this out yet.			
//				try {
//					System.out.println("Are you sure you want to exit the designer tool?");
//					String outcome = processInput();
//					continue;
//				} catch (ExitRequestException erx_2) {
//					break;
//				}

				
			}
		}
	}
	
	public String processInput()
			throws 	UserInputParseException,
					ExitRequestException
	{
		String userResponse = scanner.nextLine();
		GameCommand resultCommand = controller.parseUserInput(userResponse);
		String outcome = controller.doCommand(resultCommand);
		return outcome;
	}
}
